// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 * TEMPLATE:    SpringServiceImpl.vsl in andromda-spring cartridge
 * MODEL CLASS: AndroMDAModel::JR Appointment Service::com.systemsjr.jrappointment::user::service::UserService
 * STEREOTYPE:  Service
 */
package com.systemsjr.jrenterprise.user.service;

import java.util.Collection;

import com.systemsjr.jrenterprise.user.User;
import com.systemsjr.jrenterprise.user.UserDao;
import com.systemsjr.jrenterprise.user.vo.UserDetailsVO;
import com.systemsjr.jrenterprise.user.vo.UserSearchCriteria;
import com.systemsjr.jrenterprise.user.vo.UserVO;

/**
 * @see com.systemsjr.jrappointment.user.service.UserService
 */
public class UserServiceImpl
    extends UserServiceBase
{

    /**
     * @see com.systemsjr.jrappointment.user.service.UserService#loadAll()
     */
    protected  Collection<UserDetailsVO> handleLoadAll()
        throws Exception
    {
    	return (Collection<UserDetailsVO>) getUserDao().loadAll(UserDao.TRANSFORM_USERDETAILSVO);
    }

    /**
     * @see com.systemsjr.jrappointment.user.service.UserService#save(UserDetailsVO)
     */
    protected  UserDetailsVO handleSave(UserDetailsVO userVO)
        throws Exception
    {
    	User user = getUserDao().userDetailsVOToEntity(userVO);
    	
    	if(userVO.getId() == null){
    		
    		user = getUserDao().create(user);
    	} else{
    		getUserDao().update(user);
    	}
    	
    	return getUserDao().toUserDetailsVO(user);
    }

    /**
     * @see com.systemsjr.jrappointment.user.service.UserService#delete(UserVO)
     */
    protected  void handleDelete(UserVO userVO)
        throws Exception
    {
    	if(userVO.getId() != null){
    		getUserDao().remove(userVO.getId());
    	}
    }

    /**
     * @see com.systemsjr.jrappointment.user.service.UserService#search(UserSearchCriteria)
     */
    protected  Collection<UserDetailsVO> handleSearch(UserSearchCriteria searchCriteria)
        throws Exception
    {
    	
    	return getUserDao().toUserDetailsVOCollection(getUserDao().findByCriteria(searchCriteria));
    }

}